import { makeAutoObservable } from 'mobx';
import { ChatEntity } from '@/entities/ChatEntity';
import { TenantEntity } from '@/entities/TenantEntity';
import { LandlordEntity } from '@/entities/LandlordEntity';

class ChatStore {
  constructor() {
    makeAutoObservable(this, {}, {autoBind: true});
  }

  /**
   * chat中的senderId
   */
  senderId = '';

  /**
   * sender信息
   */
  chatSender: TenantEntity.ITenant | LandlordEntity.ILandlord;

  /**
   * receiver信息
   */
  chatReceiver: TenantEntity.ITenant | LandlordEntity.ILandlord;

  /**
   * 当前会话
   */
  currentChatSession: ChatEntity.IChatSession | any;

  /**
   * 当前用户会话列表
   */
  chatSessionList: any | ChatEntity.IChatSession[] = [];

  /**
   * 当前聊天记录
   */
  chatMessageList: any | ChatEntity.IChatMessage[] = [];

  /**
   * 会话列表的用户信息（对方）
   */
  chatReceiverInfo: any = [];

  /**
   * 会话列表的最新一条消息
   */
  chatSessionLastOneMessageList: any | ChatEntity.IChatMessage[] = [];

  /**
   * 设置chat中sender的id
   * @param senderId
   */
  setSenderId(senderId: string) {
    this.senderId = senderId;
  }

  /**
   * 设置sender信息
   */
  setChatSender(sender: any) {
    this.chatSender = sender;
  }

  /**
   * 设置receiver信息
   */
  setChatReceiver(receiver: any) {
    this.chatReceiver = receiver;
  }

  /**
   * 设置当前会话列表
   */
  setChatSessionList(chatList: ChatEntity.IChatSession[]) {
    this.chatSessionList = chatList;
  }

  /**
   * 清除会话列表
   */
  clearChatSessionList() {
    this.chatSessionList = [];
    // 清除 senderId
    this.senderId = '';
  }

  /**
   * 设置当前聊天记录
   */
  setChatMessageList(chat: ChatEntity.IChatMessage[]) {
    this.chatMessageList = chat;
  }

  /**
   * 清除当前会话聊天记录
   */
  clearChatMessageList() {
    this.chatMessageList = [];
  }

  /**
   * 设置当前会话信息
   */
  setCurrentChatSession(chatSession: ChatEntity.IChatSession) {
    this.currentChatSession = chatSession;
  }

  /**
   * 清除当前会话信息
   */
  clearCurrentChatSession() {
    this.currentChatSession = null;
  }

  /**
   * 设置会话列表的用户信息（对方）
   */
  setChatReceiverInfo(receiverInfo: any) {
    this.chatReceiverInfo = receiverInfo;
  }

  /**
   * 设置会话列表的最新一条消息
   */
  setChatSessionLastOneMessageList(messageList: ChatEntity.IChatMessage[]) {
    this.chatSessionLastOneMessageList = messageList;
  }
}

const chatStore = new ChatStore();

export default chatStore;